package cn.yqn.basic.service.impl;


import cn.yqn.basic.mapper.BaseMapper;
import cn.yqn.basic.query.BaseQuery;
import cn.yqn.basic.service.IBaseService;
import cn.yqn.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public abstract class BaseServiceImpl<T> implements IBaseService<T> {


    @Autowired
    private BaseMapper<T> baseMapper;
    /**
     * @Title: loadAll
     * @Description: 查询员工全部
     * @Author: YQN
     * @Version: 1.0
     * @Date:  2022/6/26 10:26
     * @Parameters: []
     * @Return java.util.List<cn.book.org.domain.T>
     */
    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    /**
     * @Title: loadById
     * @Description: 根据ID查询员工
     * @Author: YQN
     * @Version: 1.0
     * @Date:  2022/6/26 10:30
     * @Parameters: [id]
     * @Return cn.book.org.domain.Department
     */
    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    /**
     * @Title: remove
     * @Description: 员工删除
     * @Author: YQN
     * @Version: 1.0
     * @Date:  2022/6/26 10:34
     * @Parameters: [id]
     * @Return void
     */
    @Override
    public void remove(long id) {
        baseMapper.remove(id);
    }

    /**
     * @Title: save
     * @Description: 新增
     * @Author: YQN
     * @Version: 1.0
     * @Date:  2022/6/26 10:34
     * @Parameters: [employee]
     * @Return void
     */
    @Override
    public void save(T t) {
        baseMapper.save(t);
    }

    /**
     * @Title: update
     * @Description: 修改
     * @Author: YQN
     * @Version: 1.0
     * @Date:  2022/6/26 10:36
     * @Parameters: [employee]
     * @Return void
     */
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    /**
     * @Title: pageQuery
     * @Description: 分页
     * @Author: YQN
     * @Version: 1.0
     * @Date:  2022/6/26 10:36
     * @Parameters: [TQuery]
     * @Return java.util.List<cn.book.org.domain.T>
     */
    @Override
    public PageList<T> pageQuery(BaseQuery baseQuery) {
        // 查询全部条数
        Integer total = baseMapper.queryCount(baseQuery);
        // 查询当前页信息
        List<T> rows = baseMapper.queryData(baseQuery);
        return new PageList<>(total, rows);
    }

    /**
     * @Title: batchDel
     * @Description: 批量删除
     * @Author: YQN
     * @Version: 1.0
     * @Date:  2022/6/26 10:36
     * @Parameters: [ids]
     * @Return void
     */
    @Override
    public void patchDel(List<Long> ids) {
        baseMapper.patchDel(ids);
    }
}
